<?php
class Sys_crafts_model extends CI_Model {

	public function __construct(){
		parent::__construct();
		$this->db = $this->load->database('default',true);
	}

	public function  query_craftss() {
		$sql ="select * from sys_crafts where  be_delete ='0' and  parent_id ='$parent_id' order by crafts_id asc";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->result_array();
		}
	}

	public function query_crafts_info($crafts_id){
		$sql ="select * from  sys_crafts where  be_delete ='0' and  crafts_id ='$crafts_id' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}

	public function query_crafts_info_by_name($crafts_name){
		$sql ="select * from  sys_crafts where be_delete ='0' and  crafts_name ='$crafts_name' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}
	public function insert_crafts($crafts){
		$crafts['be_delete']=0;
		$this->db->insert('sys_crafts',$crafts);
	}
	public function update_crafts($crafts,$crafts_id){
		$this->db->where('crafts_id',$crafts_id);
		$this->db->update('sys_crafts',$crafts);
	}

	public function set_delete_crafts($crafts_id){
		$sql ="update sys_crafts set be_delete ='1' where crafts_id='$crafts_id'";
		$this->db->query($sql);
	}

	public function query_crafts_list($start,$limit) {
		$sql ="select crafts_id,crafts_name from sys_crafts where be_delete ='0'  order by crafts_id asc limit $start,$limit";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}

	public function query_crafts_num(){
		$sql ="select count(crafts_id) as num from sys_crafts  where be_delete ='0' ";
		$query =$this->db->query($sql);
		if ($query){
			$row =$query->row_array();
			return $row['num'];
		}
	}
	public function get_all_crafts(){
		$sql ="select crafts_id,crafts_name from sys_crafts where be_delete ='0'  order by crafts_id asc ";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}
}
?>